<template>
    <div>
        <rehydration-filling-machine-list ref="fmListRef"/>
        <div class="dividing-line m-t-20"></div>
        <div class="flex-end m-t-20">
            <el-button size="small" type="primary" plain @click="doCancel">取消</el-button>
            <el-button size="small" type="primary" @click="doCreate">确定创建</el-button>
        </div>

        <el-dialog title="生成工单" append-to-body :visible.sync="createTicketFlag" width="1000px">
            <rehydration-filling-machine-select-list @hide="createTicketFlag=false"
                                                     @finish="handleFinish"
                                                     :selection="selection"
                                                     v-if="createTicketFlag"/>
        </el-dialog>
    </div>
</template>

<script>
import AppPagination from "@/components/business/app-pagination";
import FillingClusterSelect from "@/components/business/filling-cluster-select";
import RehydrationFillingMachineList
    from "@/views/inventory/rehydration-ticket/components/rehydration-filling-machine-list";
import RehydrationFillingMachineSelectList
    from "@/views/inventory/rehydration-ticket/components/rehydration-filling-machine-select-list";
import {equals, listNotEmpty, msgError} from "@/util/common-util";

export default {
    name: "rehydration-ticket-create-content",
    components: {
        RehydrationFillingMachineSelectList,
        RehydrationFillingMachineList,
        FillingClusterSelect,
        AppPagination
    },
    data() {
        return {
            createTicketFlag: false,
            selection: [],

            date: '',
            data: [],
            loading: false,
            search: {
                type: '',
                status: '',
                nameOrLocation: ''
            },
            page: {
                total: 0
            },
        }
    },
    methods: {
        back(flag) {
            this.$emit('back', flag)
        },
        doCreate() {
            this.selection = this.$refs.fmListRef.getSelection()
            if (listNotEmpty(this.selection)) {
                const flag = this.selection[0].partnerName
                for (let item of this.selection) {
                    if (!equals(item.partnerName, flag)) {
                        return msgError("请选择相同主机厂的加注机，加注机" + item.macCode + "的主机厂【" + (item.partnerName === null ? '-' : item.partnerName) + "】与【" + (flag === null ? '-' : flag) + "】不相同")
                    }
                }
            }

            this.createTicketFlag = true
        },
        handleFinish() {
            this.back(true)
        },
        doCancel() {
            this.back()
        }
    }
}
</script>

